import axios from "axios"

export default {
  namespaced: true,
  state: {
    allData: {}
  },
  mutations: {
    updateAllData (state, {id, list}) {
      state.allData = {...state.allData, [id]: list}
    }
  },
  actions: {
    async getAllData (context, cataId) {
      if(context.state.allData[cataId]) {
        return
      }

      console.log(999)

      const data = await axios.get(`http://toutiao.itheima.net/v1_0/articles?channel_id=${cataId}&timestamp=${Date.now()}&with_top=1`)

      const list = data.data.data.results

      context.commit('updateAllData', {id: cataId, list: list})
    }
  }
}
